﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class MinimumScalarProduct
    {
        public MinimumScalarProduct()
        {
            int testCount = Int32.Parse(Console.ReadLine());
            for (int testCase = 1; testCase <= testCount; testCase++)
            {
                int vectorSize = Int32.Parse(Console.ReadLine());
                string[] inputA = Console.ReadLine().Split(' ');
                string[] inputB = Console.ReadLine().Split(' ');
                List<long> a = new List<long>();
                List<long> b = new List<long>();
                for (int i = 0; i < vectorSize; i++)
                {
                    a.Add(long.Parse(inputA[i]));
                    b.Add(long.Parse(inputB[i]));
                }
                a.Sort();
                b.Sort();
                b.Reverse();
                long[,] sumBoard = new long[vectorSize, vectorSize];
                for (int x = 0; x < vectorSize; x++)
                {
                    for (int y = 0; y < vectorSize; y++)
                    {
                        sumBoard[x, y] = a[x] * b[y];
                    }
                }
                long sum = 0;
                for (int i = 0; i < vectorSize; i++)
                {
                    sum += sumBoard[i, i];
                }
                Console.WriteLine("Case #" + testCase + ": " + sum);
            }
        }
    }
}
